package isssr.bean.boundary;

import isssr.bean.control.RetrieveGoalListControl;
import isssr.bean.entity.CurrentUser;
import isssr.bean.entity.OrganizationalGoal;
import isssr.bean.entity.User;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;

public class ExplorerGOBoundary implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2134786926973351965L;

	
	private List<OrganizationalGoal> 	owner_goals;	
	private CurrentUser 				current_user;
	private RetrieveGoalListControl		ctrl;
	
	public ExplorerGOBoundary(){}
	
	@PostConstruct
	private void init()
	{
		User owner = this.getCurrent_user().getUser();
		this.setOwner_goals(this.ctrl.retrieveGoalListByOwner(owner));
	}
	
	public List<OrganizationalGoal> getOwner_goals() {
		System.out.println("lista update");
		return owner_goals;
	}

	public void setOwner_goals(List<OrganizationalGoal> owner_goals) {
		this.owner_goals = owner_goals;
	}

	public CurrentUser getCurrent_user() {
		return current_user;
	}

	public void setCurrent_user(CurrentUser current_user) {
		this.current_user = current_user;
	}

	public void setCtrl(RetrieveGoalListControl ctrl) {
		this.ctrl = ctrl;
	}
	
	public void addOrganizationalGoal(OrganizationalGoal to_add)
	{
		this.owner_goals.add(to_add);
	}
	
	public void removeOrganizationalGoal(OrganizationalGoal to_remove)
	{	
		String to_remove_title = to_remove.getTitle();
		for(int i=0; i<this.owner_goals.size(); i++)
		{
			if(this.owner_goals.get(i).getTitle().equals(to_remove_title))	
				this.owner_goals.remove(i);
			
		}
	}
	
}